/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package DataAccess;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Tu
 */
public class DataManagement {

    DBUtils db;

    public DataManagement() {
        db = new DBUtils();
        db.init();
    }
    public void updateStatistic(int date, int month, int year, int income) {
        try {
            if (!(db.retriveData("select * from day where day = " + date + " and month=" + month + " and year=" + year)).next())
                db.updateData("insert into day value(" + date + "," + month + "," + year + ",0)");
            if (!(db.retriveData("select * from month where month=" + month + " and year=" + year)).next())
                db.updateData("insert into month value(" + month + "," + year + ",0)");
            if (!(db.retriveData("select * from year where year=" + year)).next())
                db.updateData("insert into year value(" + year + ",0)");
            db.updateData("update day set income = income + " + income + " where day = " + date + " and month=" + month + " and year=" + year);
            db.updateData("update month set income = income + " + income + " where month=" + month + " and year=" + year);
            db.updateData("update year set income = income + " + income + " where year=" + year);
        } catch (SQLException ex) {
            Logger.getLogger(DataManagement.class.getName()).log(Level.SEVERE, null, ex);
        }
    }                
}
